import {getCookies, removeCookies} from "util/auth";

require('./index.css');
import _tool from 'util/tool';

const page = {
    init() {
        let bmenu = getCookies('bmenu');
        bmenu = JSON.parse(bmenu);
        console.log(bmenu);
        for (let i = 0; i < bmenu.length; i++) {
            // debugger
            if (bmenu[i].type === 2) {
                $('.bread-menu-con ul').append('<li><span>&gt;</span><a data-type="1" data-parent="index" href="' + bmenu[i].parent +'.html"> Product </a></li>');
            }

            if (i === bmenu.length-1) {
                $('.bread-menu-con ul').append('<li><span>&gt;</span data-type="' + bmenu[i].type +'" data-parent="' + bmenu[i].parent + '">' + bmenu[i].name +'  </a></li>');
            } else {
                // debugger
                let prevIdHtml = '';
                if (bmenu[i].type === 2) {
                    prevIdHtml = '?pId=' + bmenu[i+1].prevId;
                } else if(bmenu[i].type === 3) {
                    prevIdHtml = '?tId=' + bmenu[i+1].prevId;
                }
                const html = '<li><span>&gt;</span><a data-type="' + bmenu[i].type +'" data-parent="' + bmenu[i].parent + '" href="' + bmenu[i+1].parent +'.html' + prevIdHtml + '"> ' + bmenu[i].name +'  </a></li>'
                $('.bread-menu-con ul').append(html);
            }
        }
        this.bindEvent();
    },
    bindEvent() {
        const goBack = function () {
            _tool.pushNode($(this));
        };
        $(document).on('click', '.bread-menu-con ul li a', goBack);
    }
};

module.export = page.init();